package com.example.backend.controller;

import com.example.backend.model.BaseModel;
import com.example.backend.service.ResponseService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("response")
public class ResponseController {
    @Resource
    private ResponseService responseService;

    @Resource
    HttpSession session;

    @Resource
    HttpServletRequest request;

    @RequestMapping(value = "addResponses", method = RequestMethod.POST)
    public BaseModel addResponses(){
        int responseId = Integer.parseInt(request.getParameter("responseId"));
        int postId = Integer.parseInt(request.getParameter("postId"));
        int userId = Integer.parseInt(request.getParameter("userId"));
        String content = request.getParameter("content");
        if(responseService.addResponses(responseId,postId,userId,content))
            return new BaseModel(0,"success");
        else
            return new BaseModel(1,"error");
    }

    @RequestMapping(value = "deleteResponses",method = RequestMethod.POST)
    public BaseModel deleteResponses(){
        int responseId = Integer.parseInt(request.getParameter("responseId"));
        if (responseService.deleteResponses(responseId))
            return new BaseModel(0,"success");
        else
            return new BaseModel(1,"error");
    }
}
